package com.gjzhao.fmmall.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Description: Swagger配置类
 * Swagger会帮助我们⽣成接⼝⽂档
 *      - 1：配置⽣成的⽂档信息
 *      -  2: 配置⽣成规则
 * @Author: gjzhao
 * @Date Created in 2021-10-30 2:18 下午
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    /**
     * Docket封装接⼝⽂档信息
     * */
    @Bean
    public Docket getDocket(){
        ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder()
                                        .title("《锋迷商城》后端-(api-order-add-feign服务)接口文档说明")
                                        .version("V1.0.0")
                                        .description("文档详细说明了后端接口规范")
                                        .contact(new Contact("gjhzao","www.jiangbk.top","gjzhao@163.com"));
        //三种对象生成方式，这里使用工厂进行生成
        ApiInfo apiInfo = apiInfoBuilder.build();

        Docket docket = new Docket(DocumentationType.SWAGGER_2)//文档风格
                        .apiInfo(apiInfo)  //指定⽣成的⽂档中的封⾯信息：⽂档标题、版本、作者
                        .select()
                        .apis(RequestHandlerSelectors.basePackage("com.gjzhao.fmmall.controller")) //指定要生成文档对controller所在的包
                        //.paths(PathSelectors.regex("/user")) //指定具体方法
                        .paths(PathSelectors.any()) //全部方法
                        .build();
        return docket;
    }

}
